package Day2025_03_14;

public class LeetCode152 {
    public int maxProduct(int[] nums) {
        int n = nums.length;
        int ret = nums[0];
        int[] f = new int[n];
        int[] g = new int[n];
        f[0] = g[0] = nums[0];
        for (int i = 1; i < n; i++) {
            int x = nums[i], y = f[i - 1] * nums[i], z = g[i - 1] * nums[i];
            f[i] = Math.max(x, Math.max(y, z));
            g[i] = Math.min(x, Math.min(y, z));
            ret = Math.max(ret, f[i]);
        }
        return ret;
    }
}
